package 行为型设计模式.动态代理模式.demo;

import java.lang.reflect.Proxy;

/**
 * @Author lf
 * @Date 3/19/2024
 */
public class ProxyDemo {
    public static void main(String[] args) {

        Calculator calculator = new BasicCalculator();

        // 创建代理对象
        Calculator proxyInstance = (Calculator)Proxy.newProxyInstance(Calculator.class.getClassLoader(), new Class[]{Calculator.class}, new CalculatorInvocationHandler(calculator));

        // 使用代理执行方法
        int result = proxyInstance.add(1, 2);

        System.out.println("Result: " + result);

    }
}
